home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / Grant's CGI Framework 1.0b14 / Util / CGI.h < prev    next >
C/C++ Source or Header  |  1996-04-12  |  9KB  |  323 lines

  1. #pragma once
  2. /*****
  3.  *
  4.  *    Grant's CGI Framework (Common Grant Interface :-)
  5.  *        http://arpp.carleton.ca/grant/mac/grantscgi/
  6.  *
  7.  *    CGI.h
  8.  *
  9.  *    standard types and function prototypes for cgi applications
  10.  *    See the Read Me or CGI.c for instructions on using the CGI Utilities
  11.  *
  12.  *    #include this file in your source files that need to access the cgi module
  13.  *
  14.  *    This is a support file for "Grant's CGI Framework".
  15.  *    Please see the license agreement that accompanies the distribution package
  16.  *    for licensing details.
  17.  *
  18.  *    Copyright ©1995,1996 by Grant Neufeld
  19.  *
  20.  *    http://arpp.carleton.ca/grant/
  21.  *    gneufeld@ccs.carleton.ca
  22.  *    grant@acm.org
  23.  *
  24.  *****/
  25.  
  26. #include "MyConfiguration.h"
  27. #if kCompileWithCGICode
  28.  
  29. #include <Threads.h>
  30.  
  31. /***  CONSTANT DECLARATIONS  ***/
  32.  
  33. #define kCGIParamMaxSize        32769
  34.  
  35. #define kCGIHTTPMethodGet                "GET"
  36. #define kCGIHTTPMethodPost                "POST"
  37. #define kCGIHTTPMethodGetConditional    "GET_CONDITIONAL"
  38.  
  39. #define kCGIFormFieldDelimiter    '='
  40. #define kCGIFormFieldSeparator    '&'
  41.  
  42. /* Apple events */
  43.  
  44. #define kAEClassCGI                'WWWΩ'
  45. #define kAEIDSearchDoc            'sdoc'
  46.  
  47. /* CGI event parameters */
  48. #define kCGIpath_args            '----'
  49. #define kCGIhttp_search_args    'kfor'
  50. #define kCGIusername            'user'
  51. #define kCGIpassword            'pass'
  52. #define kCGIfrom_user            'frmu'
  53. #define kCGIclient_address        'addr'
  54. #define kCGIpost_args            'post'
  55. #define kCGImethod                'meth'
  56. #define kCGIserver_name            'svnm'
  57. #define kCGIserver_port            'svpt'
  58. #define kCGIscript_name            'scnm'
  59. #define kCGIcontent_type        'ctyp'
  60. #define kCGIreferer                'refr'
  61. #define kCGIuser_agent            'Agnt'
  62. #define kCGIaction                'Kact'
  63. #define kCGIaction_path            'Kapt'
  64. #define kCGIclient_ip            'Kcip'
  65. #define kCGIfull_request        'Kfrq'
  66. #define kCGIversion                'Pvrs'
  67. #define kCGIconnection            'Kcid'
  68.  
  69. /* for an official listing of the maximum sizes for CGI parameters,
  70.     <http://www.biap.com/datapig/mrwheat/cgi_params.html> */
  71. #define kCGIMaxpath_args        1024
  72. #define kCGIMaxhttp_search_args    1024
  73. #define kCGIMaxusername            32
  74. #define kCGIMaxpassword            32
  75. #define kCGIMaxfrom_user        128
  76. #define kCGIMaxclient_address    256
  77. #define kCGIMaxpost_args        32768
  78. #define kCGIMaxmethod            32
  79. #define kCGIMaxserver_name        256        /* server address? */
  80. #define kCGIMaxserver_port        16
  81. #define kCGIMaxscript_name        1024
  82. #define kCGIMaxcontent_type        64
  83. #define kCGIMaxreferer            1024
  84. #define kCGIMaxuser_agent        256
  85. #define kCGIMaxaction            32
  86. #define kCGIMaxaction_path        1024
  87. #define kCGIMaxclient_ip        32
  88. #define kCGIMaxfull_request        4096
  89. //• this isn't actually a parameter of the CGI event
  90. //#define kCGIMaxversion            32768    /* ••• missing the correct value */
  91. #define kCGIMaxconnection        4
  92.  
  93. /* Action Names */
  94. #define kCGIActionNameCGI        "CGI"
  95. #define kCGIActionNameACGI        "ACGI"
  96.  
  97. /* Send Partial event */
  98. #define kMyAESendPartial        'SPar'
  99.  
  100. #define kCGIPartialData            '----'
  101. #define kConnectionIDKeyword    'Kcid'
  102. #define kMoreKeyword            'Kmor'
  103.  
  104. #define kCGIPartialStartString    "<SEND_PARTIAL>"
  105.  
  106.  
  107. /***  TYPE DECLARATIONS  ***/
  108.  
  109. #if kCompileWithCGIFormHandling
  110. typedef struct
  111. {
  112.     char *    name;
  113.     char *    value;
  114. } CGIFormField;
  115. #endif
  116.  
  117. #if kCompileWithCGImethod
  118. typedef enum
  119. {
  120.     HTTP_UNDEFINED,
  121.     HTTP_get,
  122.     HTTP_post,
  123.     HTTP_getConditional
  124. } HTTPMethod;
  125. #endif
  126.  
  127. typedef struct
  128. {
  129.     /** the following fields should be treated as public read-only **/
  130.     
  131.     #if kCompileWithCGIpath_args
  132.     char *        path_args;            /* '----' path_args            */
  133.     #endif
  134.     #if kCompileWithCGIhttp_search_args
  135.     char *        http_search_args;    /* 'kfor' http_search_args    */
  136.     #endif
  137.     #if kCompileWithCGIusername
  138.     char    username[kCGIMaxusername];    /* 'user' username            */
  139.     #endif
  140.     #if kCompileWithCGIpassword
  141.     char    password[kCGIMaxpassword];    /* 'pass' password            */
  142.     #endif
  143.     #if kCompileWithCGIfrom_user
  144.     char    from_user[kCGIMaxfrom_user];/* 'frmu' from_user            */
  145.     #endif
  146.     #if kCompileWithCGIclient_address
  147.     char    client_address[kCGIMaxclient_address];/* 'addr' client_address    */
  148.     #endif
  149.     #if kCompileWithCGIpost_args
  150.     char *        post_args;            /* 'post' post_args            */
  151.     #endif
  152.     #if kCompileWithCGImethod
  153.     HTTPMethod    method;                /* 'meth' method            */
  154.     #endif
  155.     #if kCompileWithCGIserver_name
  156.     char    server_name[kCGIMaxserver_name];/* 'svnm' server_name        */
  157.     #endif
  158.     #if kCompileWithCGIserver_port
  159.     short        server_port;        /* 'svpt' server_port        */
  160.     #endif
  161.     #if kCompileWithCGIscript_name
  162.     char *        script_name;        /* 'scnm' script_name        */
  163.     #endif
  164.     #if kCompileWithCGIcontent_type
  165.     char    content_type[kCGIMaxcontent_type];/* 'ctyp' content_type        */
  166.     #endif
  167.     #if kCompileWithCGIreferer
  168.     char *        referer;            /* 'refr' referer            */
  169.     #endif
  170.     #if kCompileWithCGIuser_agent
  171.     char    user_agent[kCGIMaxuser_agent];/* 'Agnt' user_agent        */
  172.     #endif
  173.     
  174.     #if kCompileWithCGIActionSupport
  175.     char    action[kCGIMaxaction];    /* 'Kact' action            */
  176.     char *        action_path;        /* 'Kapt' action_path        */
  177.     #endif
  178.     
  179.     #if kCompileWithCGIclient_ip
  180.     char    client_ip[kCGIMaxclient_ip];    /* 'Kcip' client_ip            */
  181.     #endif
  182.     #if kCompileWithCGIfull_request
  183.     char *        full_request;        /* 'Kfrq' full_request        */
  184.     #endif
  185. //• this isn't actually a parameter of the CGI event
  186. //    #if kCompileWithCGIversion
  187. //    char *        version;            /* 'Pvrs' version            */
  188. //    #endif
  189.     
  190.     #if kCompileWithCGISendPartial
  191.     long        connection;            /* 'Kcid' connection        */
  192.     #endif
  193.     
  194.     #if kCompileWithCGIFormHandling
  195.     CGIFormField *    formFields;        /* the fields from form submission */
  196.     long            totalFields;    /* total number of fields    */
  197.     #endif
  198.     
  199.     /** private fields that probably should not be touched outside
  200.         of the CGI.c file **/
  201.     AppleEvent        appleEvent;        /* originating appleEvent    */
  202.     AppleEvent        replyEvent;        /* apple event reply record    */
  203.     
  204.     #if kCompileWithThreadedAppleEvents
  205.     Boolean            suspended;        /* whether the AE has been suspended */
  206.     #endif
  207.     
  208. //    #if kCompileWithThreadedAppleEvents
  209. //    ThreadID        thread;            /* ID of the CGI handle's thread */
  210. //    #endif
  211.     
  212.     /** public fields to be filled in **/
  213.     #if kCompileWithCGIResponseDataAsHandle
  214.     Handle        responseData;        /* data to return to the client        */
  215.     #else
  216.     char *        responseData;        /* data to return to the client        */
  217.     #endif
  218.     long        responseSize;        /* size in bytes of the response    */
  219.     
  220.     #if kCompileWithCGIRefCon
  221.     long        refCon;                /* field for storing custom data    */
  222.     #endif
  223. } CGIrecord;
  224.  
  225. typedef CGIrecord ** CGIHdl;
  226.  
  227.  
  228. /***  GLOBAL DECLARATIONS  ***/
  229.  
  230. #ifdef __CGISegment__
  231. #define _GLOBAL_    
  232. #else
  233. #define _GLOBAL_    extern
  234. #endif
  235.  
  236. /* these are globals for holding the standard http headers.
  237.     One of the headers must be prepended to the data returned in the Apple Event */
  238.  
  239. _GLOBAL_    Str255    gHTTPHeaderOK;            /* use data returned after header    */
  240. _GLOBAL_    Str255    gHTTPHeaderRedirect;    /* redirect client to different url    */
  241. _GLOBAL_    Str255    gHTTPHeaderErr;            /* an application level error        */
  242. #if kCompileWithCGISendPartial
  243. _GLOBAL_    Str255    gHTTPHeaderPush;        /* multipart server push            */
  244. #endif
  245.  
  246. _GLOBAL_    long    gHTTPHeaderOKSize;
  247. _GLOBAL_    long    gHTTPHeaderRedirectSize;
  248. _GLOBAL_    long    gHTTPHeaderErrSize;
  249. #if kCompileWithCGISendPartial
  250. _GLOBAL_    long    gHTTPHeaderPushSize;
  251. #endif
  252.  
  253. #undef _GLOBAL_
  254.  
  255.  
  256. /***  FUNCTION PROTOTYPES  ***/
  257.  
  258.         OSErr        InitCGIUtil            ( void );
  259.         
  260.         #if kCompileWithCGIFormHandling
  261.         
  262. p_export CGIFormField *    CGIFormFieldsFromArgs    ( char *, long *, short * );
  263. p_export CGIFormField *    CGIFormFieldsFindRecord    ( CGIHdl, const char * );
  264. p_export const char *    CGIFormFieldsFindValue    ( CGIHdl, const char * );
  265.         void            CGIFormFieldsDispose    ( CGIFormField * );
  266.         
  267.         #endif    /* kCompileWithCGIFormHandling */
  268.         
  269.         #if kCompileWithCGIActionSupport
  270. p_export Boolean    CGIActionIsCGIorACGI    ( CGIHdl );
  271.         #endif
  272.         
  273. p_export void        CGIDecodeURLChars    ( char * );
  274. p_export char *        CGIEncodeURLChars    ( const char *, OSErr * );
  275. p_export Boolean    CGICharWillHex        ( unsigned char );
  276. p_export void        CGICharToHex        ( unsigned char, char * );
  277.         
  278. p_export void        CGIPathToMacPath    ( char * );
  279.         
  280. pascal    OSErr        CGIAESearchDoc        ( AppleEvent *, AppleEvent *, long );
  281.         
  282.         #if kCompileWithCGISendPartial
  283. p_export OSErr        CGIAESendPartial    ( CGIHdl, char *, long, Boolean );
  284.         #endif    /* kCompileWithCGISendPartial */
  285.         
  286. p_export void        CGILogData            ( CGIHdl );
  287.  
  288.  
  289. /***  EXTERNAL FUNCTION PROTOTYPES  ***/
  290.  
  291.     /* this is the function which you must define for your particular application */
  292. p_export void        CustomCGIProcess        ( CGIHdl );
  293.     
  294.     /* this function will be called after the cgi result has been returned.
  295.         It will contain the same CGIHdl that was used for the CustomCGIProcess */
  296. p_export void        CustomCGIPostProcess    ( CGIHdl );
  297.     
  298.     /* this function is called once at startup time.
  299.         Put any initialization you need to do in it. */
  300. p_export Boolean    CustomCGIStartup        ( void );
  301.  
  302.     /* this function is called at quitting time.
  303.         Put any cleanup you need to do in it. */
  304. p_export Boolean    CustomCGIQuit            ( Boolean );
  305.  
  306. #if !(kCompileWithout_MY_Names)
  307. #define MyCGIProcess    CustomCGIProcess
  308. #define MyCGIStartup    CustomCGIStartup
  309. #define MyCGIQuit        CustomCGIQuit
  310. #endif
  311.  
  312. #else    /* if not kCompileWithCGICode */
  313.  
  314.     /* these are defined like this here so the StartupApplication function
  315.         doesn't have to be messed with when compiling without the CGI module */
  316.     #define InitCGIUtil()        (noErr)
  317.     #define CustomCGIStartup()    (true)
  318.     #define CustomCGIQuit()        (true)
  319.  
  320. #endif    /* kCompileWithCGICode */
  321.  
  322. /***  EOF  ***/
  323.